#include "SkinWidget.h"

SkinWidget::SkinWidget(QWidget *parent)
	: BasicWindow(parent)
{
	ui.setupUi(this);

	initControl();
	loadStyleSheet("SkinWindow");
	setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
}

SkinWidget::~SkinWidget()
{
}

void SkinWidget::initControl()
{
	QVector<QColor> colors = {
		QColor(199, 237, 204),QColor(83, 167, 216),QColor(250, 249, 222),QColor(255, 242, 226),
		QColor(204, 232, 207),QColor(234, 234, 239),QColor(233, 235, 254),QColor(253, 150, 150),
		QColor(160, 238, 225),QColor(183, 232, 189),QColor(220, 226, 241),QColor(227, 237, 205)
	};

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			//ui.gridLayout.addWidget(QLabel(), i, j);
			QClickLabel *clickLabel = new QClickLabel(this);
			clickLabel->setCursor(Qt::CursorShape::PointingHandCursor);

			//QPixmap pixmap;
			//pixmap.fill(colors[(i*4+j)]);
			//clickLabel->setPixmap(pixmap);
			QPalette palette;
			palette.setColor(QPalette::ColorRole::Background, colors[(i * 4 + j)]);
			clickLabel->setPalette(palette);
			clickLabel->setAutoFillBackground(true);

			connect(clickLabel, &QClickLabel::clicked, [i, j, colors]()
			{
				NotifyManager::getInstance()->notifyOtherWindowChangeSkin(colors[(i * 4 + j)]);
			});

			ui.gridLayout->addWidget(clickLabel, i, j);
		}
	}

	connect(ui.sysmin, SIGNAL(clicked()), this, SLOT(onShowMin()));
	connect(ui.sysclose, SIGNAL(clicked()), this, SLOT(onShowClose()));
}

void SkinWidget::onShowClose()
{
	close();
}

void SkinWidget::onShowMin()
{
	this->showMinimized();
}
